package com.eb.bi.common.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class LoggerProcessor {
	private static  LoggerProcessor loggerProcessor = null;
	private static  Logger log ;
	private String m_errorDesc;
	public String getM_errorDesc() {
		return m_errorDesc;
	}

	private static LoggerProcessor initLog(){
		if(loggerProcessor == null){
			loggerProcessor = new LoggerProcessor();
		}
		return loggerProcessor;
	}
	
	public static LoggerProcessor getLogInstance(){
		return initLog();
	}
	
	public boolean startup(String logConfigFile, String category, String m_logFilePath){
		log = Logger.getLogger(category);
		Properties props = new Properties();
		try {
			InputStream in = new BufferedInputStream (new FileInputStream(logConfigFile));
			try {
				props.load(in);
				props.setProperty("log4j.appender.FILE.File", m_logFilePath);
				PropertyConfigurator.configure(props);
			} catch (IOException e) {
				this.m_errorDesc = "IOException";
				return false;
			}
		} catch (FileNotFoundException e) {
			this.m_errorDesc = "file not found exception";
			return false;
		}
		return true;
	}
	
	public void debug(String message){
		log.debug(message);
	}
	public void info(String message){
		log.info(message);
	}
	public void warn(String message){
		log.warn(message);
	}
	public void error(String message){
		log.error(message);
	}
	public void fatal(String message){
		log.fatal(message);
	}
}
